// 通知管理
<template>
  <div class="mod-salary">
    <el-select
      v-model="nickName"
      placeholder="请选择"
      clearable
      @change="monthChange()"
    >
      <el-option
        v-for="item in options"
        :key="item.userId"
        :label="item.nickName"
        :value="item.userId"
      >
      </el-option>
    </el-select>
    <el-switch
      v-model="orderType"
      active-text="升序"
      inactive-text="降序"
      @change="monthChange()"
      style="margin: 0 2vw"
    >
    </el-switch>
    <el-switch
      v-model="flag"
      active-text="有效"
      inactive-text="无效"
      @change="monthChange()"
      style="margin: 0 2vw 0 0"
    >
    </el-switch>
    <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%; margin-top: 1vw"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <el-table-column
        prop="nick_name"
        header-align="center"
        align="center"
        label="用户昵称"
      >
      </el-table-column>
      <el-table-column
        prop="notice_pub_time"
        header-align="center"
        align="center"
        label="通知时间"
      >
      </el-table-column>
      <el-table-column
        prop="notice_content"
        header-align="center"
        align="center"
        label="内容"
      >
      </el-table-column>
      <el-table-column
        prop="remark"
        header-align="center"
        align="center"
        label="备注"
      >
      </el-table-column>
      <el-table-column
        prop="flag"
        header-align="center"
        align="center"
        label="状态"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.flag == 1">有效</span>
          <span v-else>无效</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            v-if="isAuth('sys:role:update')"
            type="text"
            size="small"
            @click="addOrUpdateHandle(scope.row)"
            >修改</el-button
          >
          <!-- <el-button
            v-if="isAuth('sys:role:delete')"
            type="text"
            size="small"
            @click="deleteHandle(scope.row.id)"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <noticeAddUpdate
      ref="salaryAddUpdate"
      @refreshDataList="getDataList"
      :options="options"
    ></noticeAddUpdate>
  </div>
</template>

<script>
import noticeAddUpdate from "./notice-add-update.vue";
export default {
  name: "mod-salary",
  components: {
    noticeAddUpdate,
  },
  data() {
    return {
      nickName: "",
      dataList: [],
      options: [],
      pageIndex: 1,
      orderType: false,
      flag: true,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      addOrUpdateVisible: false,
    };
  },
  activated() {
    this.getDataList();
  },
  mounted() {
    this.getPeopleList();
  },
  methods: {
    // 人员列表
    getPeopleList() {
      this.$http({
        url: this.$http.adornUrl("/sys/user/list"),
        method: "get",
        params: this.$http.adornParams({
          page: 1,
          limit: 999,
          roleName: "",
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.options = data.page.list;
        }
      });
    },
    // 月份 筛选
    monthChange() {
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/business/enotice/query"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          noticePubId: this.nickName,
          orderType: this.orderType == true ? 2 : 1,
          flag: this.flag == true ? 1 : 0,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.records;
          this.totalPage = data.page.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.salaryAddUpdate.init(id);
      });
    },
    // 删除
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.dataListSelections.map((item) => {
            return item.department_id;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.$http({
            url: this.$http.adornUrl("/business/esalary/delete"),
            method: "get",
            params: this.$http.adornParams({
              id: ids.join(),
            }),
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.getDataList();
                },
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>
